## "replication_samplecomparisons.R" from replication package for "Registering Returning Citizens to Vote"
## This script shows the creation of several SI tables comparison current study to published work 

#####################################################################################
# Table A3: Descriptive table comparing Doleac et al. sample to Gerber et al. sample
# Table A4: Comparing impact of any treatment on registration in Doleac v. Gerber samples
# Table A5: Comparing impact of any treatment on voting in Doleac v. Gerber samples
# Table A6: Comparing impact of each treatment on registration in Doleac v. Gerber samples
# Table A7: Comparing impact of each treatment on voting in Doleac v. Gerber samples
#####################################################################################

rm(list=ls())
library(data.table)
library(stargazer)
library(xtable)
library(dplyr)

# objective is to see if we can split the sample
# so that it's in keeping with the Gerber et al. sample
# and then re-evaluate the impact of the treatment among more-comparable subsamples.

#pull in main analysis dataset
main <- read_csv("main_paper_2025.csv")
data <- main[main$list == "NCmainlist",]

# set up indicator for any treatment (ie not control), rather than separate arms
data$anytreat <- 1; 
data[data$Treatment == "T1", "anytreat"] <- 0; table(data$anytreat)

# code sentences that are akin to those Gerber et al. omitted
data$CIPRIOFF <- trimws(data$CIPRIOFF)

data <- data %>% mutate(gerber_omit_offense = case_when(CIPRIOFF =="??????????????????????????????"~"y",
                                                    CIPRIOFF =="2ND DEGREE FORCIBLE RAPE"~"y",
                                                    CIPRIOFF =="ABANDONMENT OF CHILD 6 MONTHS"~"y",
                                                    CIPRIOFF =="ABDUCTION OF CHILD(REGISTER)"~"y",
                                                    CIPRIOFF =="ABDUCTION/CHILD(NON-REGISTER)"~"y",
                                                    CIPRIOFF =="ACCESSORY/AFTER/FACT/ANY FELON"~"n",
                                                    CIPRIOFF =="AGG FEL SERIOUS INJ VEHICLE"~"y",
                                                    CIPRIOFF =="AGG FELONY DEATH BY VEHICLE"~"y",
                                                    CIPRIOFF =="AISI DETENTION EMPLOYEE W/DUTY"~"n",
                                                    CIPRIOFF =="AISI LAW/PROB/PAR OFFIC W/DUTY"~"n",
                                                    CIPRIOFF =="ALTER SERIAL NUMBER"~"n",
                                                    CIPRIOFF =="ARMED ROBBERY"~"m",
                                                    CIPRIOFF =="ARSON & BURNINGS"~"n",
                                                    CIPRIOFF =="ARSON 1ST DEGREE"~"m",
                                                    CIPRIOFF =="ARSON 2ND DEGREE"~"m",
                                                    CIPRIOFF =="ASLT PHYINJ LAW OFFCR/DENT EMP"~"y",
                                                    CIPRIOFF =="ASSAULT BY STRANGULATION"~"m",
                                                    CIPRIOFF =="ASSAULT INFLICT SERI BODY INJ"~"m",
                                                    CIPRIOFF =="ASSAULT ISI"~"m",
                                                    CIPRIOFF =="ASSAULT ISI EXEC/LEGIS OFFICER"~"m",
                                                    CIPRIOFF =="ASSAULT ON EXEC/LEGIS OFFICER"~"m",
                                                    CIPRIOFF =="ASSAULT ON FEMALE"~"m",
                                                    CIPRIOFF =="ASSAULT ON HANDICAPPED"~"m",
                                                    CIPRIOFF =="ASSAULT ON OFFICER/ST EMPLOYEE"~"m",
                                                    CIPRIOFF =="ASSAULT ON POLICEMAN"~"m",
                                                    CIPRIOFF =="ASSAULT ON PUBLIC OFFICIAL"~"m",
                                                    CIPRIOFF =="ASSAULT W/FIREARM LAW ENF OFFC"~"m",
                                                    CIPRIOFF =="ASSAULT WDW EXEC/LEGIS OFFICER"~"m",
                                                    CIPRIOFF =="ASSAULT,AFFRAY ON EMERG. MED"~"m",
                                                    CIPRIOFF =="ASSAULT/THR AGNST GOVERNMNT"~"m",
                                                    CIPRIOFF =="ATT FIRST DEG MURDER"~"y",
                                                    CIPRIOFF =="AWDW"~"n",
                                                    CIPRIOFF =="AWDW GOV OFFICERS/EMPLOYEES"~"n",
                                                    CIPRIOFF =="AWDWISI"~"n",
                                                    CIPRIOFF =="AWDWWITK"~"n",
                                                    CIPRIOFF =="AWDWWITKISI"~"n",
                                                    CIPRIOFF =="B & E & L"~"n",
                                                    CIPRIOFF =="B & E VEHICLES"~"n",
                                                    CIPRIOFF =="B & E VENDING MACHINES"~"n",
                                                    CIPRIOFF =="B&E HOUSE OF WORSHIP"~"n",
                                                    CIPRIOFF =="B&E PAPER CURRENCY MACHINE 1ST"~"n",
                                                    CIPRIOFF =="B&E PAPER CURRENCY MACHINE 2ND"~"n",
                                                    CIPRIOFF =="B&E W/INTENT/TERRORIZE/INJURE"~"n",
                                                    CIPRIOFF =="BAN NETWORK WEBSITE BY SEXOFF"~"y",
                                                    CIPRIOFF =="BIGAMY"~"n",
                                                    CIPRIOFF =="BOMB THREAT"~"n",
                                                    CIPRIOFF =="BURGLARY"~"n",
                                                    CIPRIOFF =="BURGLARY 1ST DEGREE"~"n",
                                                    CIPRIOFF =="BURGLARY 2ND DEGREE"~"n",
                                                    CIPRIOFF =="BURN BRIDGE,FIREHOUSE,BUSINESS"~"n",
                                                    CIPRIOFF =="BURN CHURCH, RELIGIOUS BLDG"~"n",
                                                    CIPRIOFF =="BURN UNINHABITED BUILDING"~"n",
                                                    CIPRIOFF =="BURNING EDUCATION/SCH BLD"~"n",
                                                    CIPRIOFF =="BURNING OTHER PROPERTY"~"n",
                                                    CIPRIOFF =="BURNING PERSONAL PROPERTY"~"n",
                                                    CIPRIOFF =="BURNING PRIVATE PROPERTY"~"n",
                                                    CIPRIOFF =="BURNING PUBLIC BUILDING"~"n",
                                                    CIPRIOFF =="CARRY CONCEALED WEAPON"~"n",
                                                    CIPRIOFF =="CHEAT - PROPERTY/SERVICES"~"n",
                                                    CIPRIOFF =="CHILD ABUSE"~"y",
                                                    CIPRIOFF =="CHILD ABUSE - INTENT ISBI"~"y",
                                                    CIPRIOFF =="CHILD ABUSE ISI"~"y",
                                                    CIPRIOFF =="CHILD ABUSE SEXUAL ACT"~"y",
                                                    CIPRIOFF =="CHOP SHOP ACTIVITY"~"n",
                                                    CIPRIOFF =="COM L FALSE IMPRISONMENT"~"n",
                                                    CIPRIOFF =="COM L FELONY AID AND ABET"~"n",
                                                    CIPRIOFF =="COM L FELONY NO STATUTE"~"n",
                                                    CIPRIOFF =="COM LAW ARM TERROR PEOPLE"~"n",
                                                    CIPRIOFF =="COMMON LAW FORGERY"~"n",
                                                    CIPRIOFF =="COMMON LAW ROBBERY"~"n",
                                                    CIPRIOFF =="CONCEAL EVD DEATH UNNAT CAUSE"~"n",
                                                    CIPRIOFF =="CONSPIRACY"~"n",
                                                    CIPRIOFF =="CONT CRIMINAL ENTERPRISE"~"n",
                                                    CIPRIOFF =="CONVERSION BY BAILEE"~"n",
                                                    CIPRIOFF =="COUNTERFEITING"~"n",
                                                    CIPRIOFF =="CREDIT CARD FORGERY"~"n",
                                                    CIPRIOFF =="CREDIT CARD THEFT"~"n",
                                                    CIPRIOFF =="CRIME AGAINST NATURE"~"n",
                                                    CIPRIOFF =="CRUELTY TO ANIMALS"~"n",
                                                    CIPRIOFF =="DAMAGE COMPUTER, SYSTEM, NETWK"~"n",
                                                    CIPRIOFF =="DAMAGE W/EXPLOSIVES"~"n",
                                                    CIPRIOFF =="DEATH BY VEHICLE"~"y",
                                                    CIPRIOFF =="DEATH BY VEHICLE  FELONY"~"y",
                                                    CIPRIOFF =="DEL/SELL SCHEDULE I"~"n",
                                                    CIPRIOFF =="DEL/SELL SCHEDULE II"~"n",
                                                    CIPRIOFF =="DEL/SELL SCHEDULE III"~"n",
                                                    CIPRIOFF =="DEL/SELL SCHEDULE IV"~"n",
                                                    CIPRIOFF =="DEL/SELL SCHEDULE VI"~"n",
                                                    CIPRIOFF =="DESTROY EVIDENCE"~"n",
                                                    CIPRIOFF =="DISC/FIREARM-PROP/SERI BODY"~"y",
                                                    CIPRIOFF =="DISC/FIREARM/INCITE/FEAR"~"n",
                                                    CIPRIOFF =="DISC/FIREARM/OCCUPIED VEHICLE"~"n",
                                                    CIPRIOFF =="DISCHG FIREARM-OCC PROPERTY"~"n",
                                                    CIPRIOFF =="DISSEM MINOR LS 13"~"n",
                                                    CIPRIOFF =="DIST FOOD INJURIOUS TO HLTH"~"n",
                                                    CIPRIOFF =="DOMESTIC ABUSE DISABLED/ELDER"~"m",
                                                    CIPRIOFF =="DRIV LICENSE REVOKED"~"n",
                                                    CIPRIOFF =="DRIVING UNDER INFLUENCE (DUI)"~"n",
                                                    CIPRIOFF =="DRUG PARA - USE/POSSESS"~"n",
                                                    CIPRIOFF =="DVPO VIOL DEADLY/WEAPON"~"n",
                                                    CIPRIOFF =="DWI DRIVING WHILE IMPAIRED"~"n",
                                                    CIPRIOFF =="DWI LEVEL 1"~"n",
                                                    CIPRIOFF =="DWI LEVEL 2"~"n",
                                                    CIPRIOFF =="DWI LEVEL 3"~"n",
                                                    CIPRIOFF =="DWI LEVEL 4"~"n",
                                                    CIPRIOFF =="DWI LEVEL 5"~"n",
                                                    CIPRIOFF =="EMBEZZLE CS BY EMPLOY OF REG"~"n",
                                                    CIPRIOFF =="EMBEZZLEMENT"~"n",
                                                    CIPRIOFF =="EMBEZZLEMENT - COMMERCIAL"~"n",
                                                    CIPRIOFF =="EMBEZZLEMENT - PUBLIC"~"n",
                                                    CIPRIOFF =="EMBEZZLEMENT-OFFICE/EMPLOYMENT"~"n",
                                                    CIPRIOFF =="EMBEZZLEMENT-PARTNER FUNDS"~"n",
                                                    CIPRIOFF =="EMBEZZLEMENT-STATE PROPERTY"~"n",
                                                    CIPRIOFF =="EMBEZZLEMENT-TRUSTEES"~"n",
                                                    CIPRIOFF =="EMPLOY MIN DRUG VIOLATION"~"n",
                                                    CIPRIOFF =="ESCAPE JAIL BY FELON"~"n",
                                                    CIPRIOFF =="ESCAPE PRISON"~"n",
                                                    CIPRIOFF =="EXPLOIT ELDER/DISABLED ADULT"~"m",
                                                    CIPRIOFF =="EXPLOSIVES - POSS/SELL"~"n",
                                                    CIPRIOFF =="EXTORTION"~"n",
                                                    CIPRIOFF =="FAIL TO REGISTER (SEX OFFENDER"~"y",
                                                    CIPRIOFF =="FAIL VERFY ADDR SEXOFFENDR"~"y",
                                                    CIPRIOFF =="FAIL/NOTFY CHG ADDR SEXOFF"~"y",
                                                    CIPRIOFF =="FAIL/NOTIFY DMV CHG ADDRESS"~"n",
                                                    CIPRIOFF =="FAILING TO RETURN RENTED PROPE"~"n",
                                                    CIPRIOFF =="FAILURE TO APPEAR"~"n",
                                                    CIPRIOFF =="FAILURE TO APPEAR FELONY"~"n",
                                                    CIPRIOFF =="FAILURE TO MAKE REPORT"~"n",
                                                    CIPRIOFF =="FAILURE TO RETURN PROCESS"~"n",
                                                    CIPRIOFF =="FAILURE TO STOP FOR ACCIDENT"~"n",
                                                    CIPRIOFF =="FALSE BOMB REPORT PUBLIC BLDG"~"n",
                                                    CIPRIOFF =="FALSE STATE INSURANCE BENEFITS"~"n",
                                                    CIPRIOFF =="FALSE VERIF/NOT SEXOFFENDR"~"y",
                                                    CIPRIOFF =="FEL RESTRAINT OF A MINOR"~"n",
                                                    CIPRIOFF =="FELONIOUS ASSAULT HANDICAPPED"~"n",
                                                    CIPRIOFF =="FELONIOUS RESTRAINT"~"n",
                                                    CIPRIOFF =="FELONY B&E"~"n",
                                                    CIPRIOFF =="FELONY INDECENT EXPOSURE"~"y",
                                                    CIPRIOFF =="FINANCIAL CARD FRAUD/FELON"~"n",
                                                    CIPRIOFF =="FINANCIAL CARD FRAUD/MISD"~"n",
                                                    CIPRIOFF =="FIRST DEGREE TRESPASS"~"n",
                                                    CIPRIOFF =="FOOD STAMP FRAUD > $400"~"n",
                                                    CIPRIOFF =="FORGERY"~"n",
                                                    CIPRIOFF =="FORGERY AND UTTERING"~"n",
                                                    CIPRIOFF =="FORGERY BANK NOTES"~"n",
                                                    CIPRIOFF =="FRAUD"~"n",
                                                    CIPRIOFF =="FRAUD BURNING DWELLING"~"n",
                                                    CIPRIOFF =="FRAUD MISREP- FOOD STAMP AMT"~"n",
                                                    CIPRIOFF =="GIV/SEL/MOB/OTHER/DEV/INMATE"~"n",
                                                    CIPRIOFF =="HABITUAL BREAKING AND ENTERING"~"n",
                                                    CIPRIOFF =="HABITUAL FELON"~"n",
                                                    CIPRIOFF =="HABITUAL IMPAIRED DRIVING"~"n",
                                                    CIPRIOFF =="HABITUAL MISDEMEANOR ASSAULT"~"n",
                                                    CIPRIOFF =="HABITUAL OFFENDER"~"n",
                                                    CIPRIOFF =="HIT AND RUN"~"y",
                                                    CIPRIOFF =="HIT/RUN INJURY"~"y",
                                                    CIPRIOFF =="HIT/RUN SER INJ/DEATH"~"y",
                                                    CIPRIOFF =="IDENTITY FRAUD/THEFT"~"n",
                                                    CIPRIOFF =="INCEST - FELON"~"y",
                                                    CIPRIOFF =="INCITING TO RIOT"~"n",
                                                    CIPRIOFF =="INDECENT LIBERTY W/CHILD"~"y",
                                                    CIPRIOFF =="INJ PROP/OBTN NOFERROUS METAL"~"n",
                                                    CIPRIOFF =="INJURE HOUSE,CHURCH,FENCE ETC"~"n",
                                                    CIPRIOFF =="INJURE WIRES OF TELE/TELG CO"~"n",
                                                    CIPRIOFF =="INMATE/PSS/TABC/MOB/OTHER/DEV"~"n",
                                                    CIPRIOFF =="INSURANCE FRAUD"~"n",
                                                    CIPRIOFF =="INTERFERE/ELECT MONITOR DEV"~"n",
                                                    CIPRIOFF =="INTIMIDATE WITNESSES"~"n",
                                                    CIPRIOFF =="INVOLUNTARY MANSLAUGHTER"~"y",
                                                    CIPRIOFF =="KIDNAPPING 1ST DEG OF A MINOR"~"y",
                                                    CIPRIOFF =="KIDNAPPING 1ST DEGREE"~"n",
                                                    CIPRIOFF =="KIDNAPPING 2ND DEG OF A MINOR"~"y",
                                                    CIPRIOFF =="KIDNAPPING 2ND DEGREE"~"n",
                                                    CIPRIOFF =="KIDNAPPING/ABDUCTION"~"n",
                                                    CIPRIOFF =="LARCENY"~"n",
                                                    CIPRIOFF =="LARCENY (OVER $200)"~"n",
                                                    CIPRIOFF =="LARCENY AFTER B & E"~"n",
                                                    CIPRIOFF =="LARCENY BY SERVANT/EMPLOYEE"~"n",
                                                    CIPRIOFF =="LARCENY FROM CONSTRUCTION SITE"~"n",
                                                    CIPRIOFF =="LARCENY FROM MERCHANT"~"n",
                                                    CIPRIOFF =="LARCENY FROM PERSON"~"n",
                                                    CIPRIOFF =="LARCENY OF BANK NOTES, BONDS"~"n",
                                                    CIPRIOFF =="LARCENY OF DOGS"~"n",
                                                    CIPRIOFF =="LARCENY OF FIREARMS"~"n",
                                                    CIPRIOFF =="LARCENY OF GINSENG"~"n",
                                                    CIPRIOFF =="LARCENY OF HORSES/MULES/SWINE"~"n",
                                                    CIPRIOFF =="LARCENY OF MOTOR VEHICLE"~"n",
                                                    CIPRIOFF =="LARCENY OVER $1000"~"n",
                                                    CIPRIOFF =="MAINT ANY PLACE CONTR SUB"~"n",
                                                    CIPRIOFF =="MALFEASANCE OF CORP OF AND AGT"~"n",
                                                    CIPRIOFF =="MALICIOUS CONDUCT/PRISONER"~"n",
                                                    CIPRIOFF =="MALICIOUS MAIMING"~"n",
                                                    CIPRIOFF =="MANSLAUGHTER"~"y",
                                                    CIPRIOFF =="MANUFACTURE CONTROL SUBSTANCE"~"n",
                                                    CIPRIOFF =="MANUFACTURE METHAMPHETAMINE"~"n",
                                                    CIPRIOFF =="MANUFACTURE SCHEDULE I"~"n",
                                                    CIPRIOFF =="MANUFACTURE SCHEDULE II"~"n",
                                                    CIPRIOFF =="MANUFACTURE SCHEDULE VI"~"n",
                                                    CIPRIOFF =="MISD B&E"~"n",
                                                    CIPRIOFF =="MULTIPLE PRIOR LARCENIES"~"n",
                                                    CIPRIOFF =="MURDER FIRST DEGREE"~"y",
                                                    CIPRIOFF =="MURDER SECOND DEGREE"~"y",
                                                    CIPRIOFF =="NON-MALICIOUS CASTRAT/MAIME"~"n",
                                                    CIPRIOFF =="NON/COMP-FAIL TO REG SEX OFF"~"y",
                                                    CIPRIOFF =="OBSCENE LITERATURE"~"n",
                                                    CIPRIOFF =="OBSTRUCTING JUSTICE"~"n",
                                                    CIPRIOFF =="OBT PROP BY FALSE PR/CHTS/SER"~"n",
                                                    CIPRIOFF =="OBTAIN CONTR SUBST BY FRAUD"~"n",
                                                    CIPRIOFF =="OBTAIN PROPERTY-WORTHLESS CKS"~"n",
                                                    CIPRIOFF =="OFFER BRIBE TO OFFICIAL"~"n",
                                                    CIPRIOFF =="OPERATE RED/BLUE LIGHT ON VEH"~"n",
                                                    CIPRIOFF =="OPERATE VEHICLE W/O LICENSE"~"n",
                                                    CIPRIOFF =="ORGANIZED RETAIL THEFT"~"n",
                                                    CIPRIOFF =="OTHER FELON"~"n",
                                                    CIPRIOFF =="PARTICPAT IN PROSTIT OF MINOR"~"y",
                                                    CIPRIOFF =="PASSENGER FLEE ACCIDENT/INJURY"~"n",
                                                    CIPRIOFF =="PATIENT ABUSE & NEGLECT"~"m",
                                                    CIPRIOFF =="PEEPING TOM/SECRETLY PEEPING"~"n",
                                                    CIPRIOFF =="PERJURY"~"n",
                                                    CIPRIOFF =="POSS FIREARM/REMOVAL SERIAL NB"~"n",
                                                    CIPRIOFF =="POSS PRECURSOR WIT MANUFACTURE"~"n",
                                                    CIPRIOFF =="POSS/CARRY BB GUN/RIFLE ED PRO"~"n",
                                                    CIPRIOFF =="POSS/DIST PREC CONTR SUBST"~"n",
                                                    CIPRIOFF =="POSS/DISTRI METH PRECURSOR"~"n",
                                                    CIPRIOFF =="POSS/TRANS COUNTERFEIT INST."~"n",
                                                    CIPRIOFF =="POSSESS CONTROL SUBSTANCE"~"n",
                                                    CIPRIOFF =="POSSESS SCHEDULE I"~"n",
                                                    CIPRIOFF =="POSSESS SCHEDULE II"~"n",
                                                    CIPRIOFF =="POSSESS SCHEDULE III"~"n",
                                                    CIPRIOFF =="POSSESS SCHEDULE IV"~"n",
                                                    CIPRIOFF =="POSSESS SCHEDULE VI"~"n",
                                                    CIPRIOFF =="POSSESS WEAPON MASS DEST"~"n",
                                                    CIPRIOFF =="POSSESS WIT SELL CONTROL SUBST"~"n",
                                                    CIPRIOFF =="POSSESS WITS SCHEDULE I"~"n",
                                                    CIPRIOFF =="POSSESS WITS SCHEDULE II"~"n",
                                                    CIPRIOFF =="POSSESS WITS SCHEDULE III"~"n",
                                                    CIPRIOFF =="POSSESS WITS SCHEDULE IV"~"n",
                                                    CIPRIOFF =="POSSESS WITS SCHEDULE VI"~"n",
                                                    CIPRIOFF =="POSSESSING STOLEN GOODS"~"n",
                                                    CIPRIOFF =="POSSESSION OF BURGLARY TOOLS"~"n",
                                                    CIPRIOFF =="POSSESSION OF FIREARM BY FELON"~"n",
                                                    CIPRIOFF =="POSSESSION OF WEAPON ON CAMPUS"~"n",
                                                    CIPRIOFF =="PREPARATION TO COMMIT BURGLARY"~"n",
                                                    CIPRIOFF =="PROMOTE PROSTITUTION OF MINOR"~"y",
                                                    CIPRIOFF =="PROMOTING PROSTITUTION"~"n",
                                                    CIPRIOFF =="PUBLIC ASSISTANCE FRAUD > $400"~"n",
                                                    CIPRIOFF =="PURCH FIREARM BY PERSON PROHIB"~"n",
                                                    CIPRIOFF =="PWISD COUNTERFEIT CS"~"n",
                                                    CIPRIOFF =="RAPE FIRST DEGREE"~"y",
                                                    CIPRIOFF =="RAPE LESS THAN AGE 13"~"y",
                                                    CIPRIOFF =="RAPE SECOND DEGREE"~"y",
                                                    CIPRIOFF =="RECEIVING STOLEN GOODS"~"n",
                                                    CIPRIOFF =="RECEIVING STOLEN VEHICLE"~"n",
                                                    CIPRIOFF =="RECEIVING/POSSESSING FIREARM"~"n",
                                                    CIPRIOFF =="RIOT & CIVIL DISORDERS"~"n",
                                                    CIPRIOFF =="ROBBERY"~"n",
                                                    CIPRIOFF =="ROBBERY W/DANGEROUS WEAPON"~"n",
                                                    CIPRIOFF =="S/D CONT SUB PUBLIC PARK 21>"~"n",
                                                    CIPRIOFF =="S/D CONTL SUB ON SCHOOL PROPTY"~"n",
                                                    CIPRIOFF =="S/D CS PERSON 18 TO UNDER 16"~"n",
                                                    CIPRIOFF =="SAFECRACKING/SAFE ROBBERY"~"n",
                                                    CIPRIOFF =="SELL CONTROL SUBSTANCE"~"n",
                                                    CIPRIOFF =="SELL SCHEDULE I"~"n",
                                                    CIPRIOFF =="SELL SCHEDULE II"~"n",
                                                    CIPRIOFF =="SELL SCHEDULE III"~"n",
                                                    CIPRIOFF =="SELL SCHEDULE IV"~"n",
                                                    CIPRIOFF =="SELL SCHEDULE VI"~"n",
                                                    CIPRIOFF =="SERIOUS INJ B/VEHICLE FEL"~"m",
                                                    CIPRIOFF =="SEX ACT W/STUDENT BY TEACHER"~"y",
                                                    CIPRIOFF =="SEX EXPLOIT MINOR 1ST DEGREE"~"y",
                                                    CIPRIOFF =="SEX EXPLOIT MINOR 2ND DEGREE"~"y",
                                                    CIPRIOFF =="SEX EXPLOIT MINOR 3RD DEGREE"~"y",
                                                    CIPRIOFF =="SEX OFFENDER/CHILD PREMISES"~"y",
                                                    CIPRIOFF =="SEX OFFSE SUB PARENT/CUSTODIAN"~"y",
                                                    CIPRIOFF =="SEXOFFENDR RESIDENCE VIOLATION"~"n",
                                                    CIPRIOFF =="SEXUAL BATTERY"~"y",
                                                    CIPRIOFF =="SEXUAL OFF 1ST DEGR W/CHILD"~"y",
                                                    CIPRIOFF =="SEXUAL OFF 1ST DEGREE ISI"~"y",
                                                    CIPRIOFF =="SEXUAL OFFENSE 1ST DEGREE"~"y",
                                                    CIPRIOFF =="SEXUAL OFFENSE 2ND DEGREE"~"y",
                                                    CIPRIOFF =="SHOPLIFT CONCEAL DEVICE"~"n",
                                                    CIPRIOFF =="SHOPLIFTING"~"n",
                                                    CIPRIOFF =="SOL SEX BY COMPUTER /CHILD"~"y",
                                                    CIPRIOFF =="SOL.TO COMMIT 1ST DEG MURDER"~"n",
                                                    CIPRIOFF =="SOL.TO COMMIT FELONY/MISD"~"n",
                                                    CIPRIOFF =="SPECTATOR OF ANIMAL FIGHTS"~"n",
                                                    CIPRIOFF =="SPEED ELUDE ARREST/ATTEMPT/SEC"~"n",
                                                    CIPRIOFF =="SPEED ELUDE ARRST MV/DEATH/2AF"~"n",
                                                    CIPRIOFF =="SPEEDING ELUDE ARREST OR/ATTEM"~"n",
                                                    CIPRIOFF =="STALKING"~"n",
                                                    CIPRIOFF =="STAT RAPE/SEX OFFN < 6YR"~"y",
                                                    CIPRIOFF =="STAT RAPE/SEX OFFN >= 6 YR"~"y",
                                                    CIPRIOFF =="TAMPER WITH SAT-BASED MONITOR"~"n",
                                                    CIPRIOFF =="THREAT ISI EXEC/LEGIS OFFICER"~"n",
                                                    CIPRIOFF =="TRAFF/STOLEN IDENTITIES"~"n",
                                                    CIPRIOFF =="TRAFFICK COCAINE >400 GRAMS"~"n",
                                                    CIPRIOFF =="TRAFFICK COCAINE 14-27 GRAMS"~"n",
                                                    CIPRIOFF =="TRAFFICK COCAINE 200-399 GRAMS"~"n",
                                                    CIPRIOFF =="TRAFFICK COCAINE 28-199 GRAMS"~"n",
                                                    CIPRIOFF =="TRAFFICK MARIJUANA 50-99 LBS"~"n",
                                                    CIPRIOFF =="TRAFFICK METHAQUALON 5000-9999"~"n",
                                                    CIPRIOFF =="TRAFFICK OPIUM/HEROIN 14-27 GR"~"n",
                                                    CIPRIOFF =="TRAFFICK OPIUM/HEROIN 28 GRAMS"~"n",
                                                    CIPRIOFF =="TRAFFICK OPIUM/HEROIN 4-13 GRA"~"n",
                                                    CIPRIOFF =="TRAFFICKING CONTROLLED SUBSTAN"~"n",
                                                    CIPRIOFF =="TRAFFICKING IN METHAMPHETAMINE"~"n",
                                                    CIPRIOFF =="TRAFFICKING SCHEDULE I"~"n",
                                                    CIPRIOFF =="TRAFFICKING SCHEDULE II"~"n",
                                                    CIPRIOFF =="TRAFFICKING SCHEDULE IV"~"n",
                                                    CIPRIOFF =="TRAFFICKING SCHEDULE VI"~"n",
                                                    CIPRIOFF =="UTTERING FORGEDPAPER/INST/END"~"n",
                                                    CIPRIOFF =="VIOLATION CONT SUB PENAL INST"~"n",
                                                    CIPRIOFF =="VIOLATION DRUG LAWS"~"n",
                                                    CIPRIOFF =="VIOLATION PROTECTIVE ORDER"~"n",
                                                    CIPRIOFF =="VIOLATION SOCIAL SERVICES LAWS"~"n",
                                                    CIPRIOFF =="WEAP/NARC/ALCHL TO INMATE"~"n",
                                                    CIPRIOFF =="WORTHLESS CHECK"~"n",
                                                    CIPRIOFF =="WORTHLESS CHECKS OVER $2000"~"n"))


table(data$gerber_omit_offense) 

# Let's see if we can ID whether people have been out for more or less than three years
# let's call 10/1 our treatment date
data <- data %>% mutate(treatment_date = as.Date("2020-10-01"),
                        lastincarcend = as.Date(lastincarcend),
                        years_released = (treatment_date - lastincarcend)/365,
                        gerber_omit_timereleased = ifelse(years_released > 3,1,0))

# a lot of people to omit because of time released
table(data$gerber_omit_timereleased)

# Ok, so with this variable, we want to know who in our sample would have been included in Gerber et al.'s sample 
# 1 = gerber sample, 0 = everyone else, even those who were not incarcerated; 
# we can isolate only those who were previously incarcerated using "pastincarc"
data <- data %>% mutate(gerber_sample = ifelse(c(gerber_omit_offense=="y" | gerber_omit_timereleased==1),0,1 ))
data$gerber_sample[is.na(data$gerber_sample)] <- 0   


# first I want a descriptive table just showing how many people in our sample overlap with Gerber et al's
tot <- "35245"
violent <- table(data$gerber_omit_offense[data$gerber_omit_offense=="y"])
time_released <- table(data$gerber_omit_timereleased[data$gerber_omit_timereleased==1])
never_inc <- table(data$pastincarc[data$pastincarc==0])
gerber_comp <- table(data$gerber_sample[data$gerber_sample==1]) 

names(violent) <- NULL
names(time_released) <- NULL
names(never_inc) <- NULL
names(gerber_comp) <- NULL

table<- rbind(tot,never_inc, violent, time_released,gerber_comp)
rownames(table) <- c("Total sample","Never incarcerated","Omitted Offenses","Out for 3+ years","Gerber comparable sample")
colnames(table) <- c("N value")
dim(table)

library(xtable)

xt <- xtable(
  x = table,
  align = "lc",
  type = "html",
  caption = "Doleac et al. vs. Gerber et al. Samples",
  label = "tab:descriptive"
)

addtorow <- list()
addtorow$pos <- list(nrow(xt))

print(xt,
      format.args = list(big.mark = ","),
      caption.placement = "top",
      file = "doleacVgerber.tex",
      hline.after = c(-1, 0, 5))
#TABLE A3

# now some models
m1<-lm(reg2020 ~ anytreat, data=data)
m2<-lm(reg2020 ~ anytreat, data=data %>% filter(pastincarc == 1))
m3<-lm(reg2020 ~ anytreat, data=data %>% filter(gerber_omit_offense != "y"))
m4<-lm(reg2020 ~ anytreat, data=data %>% filter(gerber_omit_timereleased == 0))
m5<-lm(reg2020 ~ anytreat, data=data %>% filter(gerber_sample==1))


stargazer(m1,m2,m3,m4,m5, 
          omit.stat="f",
          column.sep.width = "-5pt",
          covariate.labels=c("Any mailer"), 
          title="Impact of receiving any mailer on registration, by sample",
          dep.var.labels="", digits=1,
          dep.var.caption = "",
          column.labels = c("Total sample","Incarcerated (only)","Violent offenses (omitted)","Out for 3+ (omitted)","Gerber comparable"),
          font.size = "scriptsize",
          label = "doleacVgerberRegModels",
          out = "doleacVgerber_regmodels.tex"
          )

m1<-lm(voted2020gen ~ anytreat, data=data)
m2<-lm(voted2020gen ~ anytreat, data=data %>% filter(pastincarc == 1))
m3<-lm(voted2020gen ~ anytreat, data=data %>% filter(gerber_omit_offense != "y"))
m4<-lm(voted2020gen ~ anytreat, data=data %>% filter(gerber_omit_timereleased == 0))
m5<-lm(voted2020gen ~ anytreat, data=data %>% filter(gerber_sample==1))

stargazer(m1,m2,m3,m4,m5, 
          omit.stat="f",
          column.sep.width = "-5pt",
          covariate.labels=c("Any mailer"), 
          title="Impact of receiving any mailer on voting in 2020, by sample",
          dep.var.labels="", digits=1,
          dep.var.caption = "",
          column.labels = c("Total sample","Incarcerated (only)","Violent offenses (omitted)","Out for 3+ (omitted)","Gerber comparable"),
          font.size = "scriptsize",
          label = "doleacVgerberVoteModels",
          out = "doleacVgerber_votemodels.tex"
          )


### by treatment arm

m1<-lm(reg2020 ~ as.factor(Treatment), data=data)
m2<-lm(reg2020 ~ as.factor(Treatment), data=data %>% filter(pastincarc == 1))
m3<-lm(reg2020 ~ as.factor(Treatment), data=data %>% filter(gerber_omit_offense != "y"))
m4<-lm(reg2020 ~ as.factor(Treatment), data=data %>% filter(gerber_omit_timereleased == 0))
m5<-lm(reg2020 ~ as.factor(Treatment), data=data %>% filter(gerber_sample==1))

stargazer(m1,m2,m3,m4,m5, 
          omit.stat="f",
          title="Impact of each treatment on registration, by sample",
          dep.var.labels="", digits=1,
          dep.var.caption = "",
          column.sep.width = "-5pt",
          covariate.labels=c("Basic mailer", "No criminal record framing", "No registration form", "Extra civil rights framing"), 
          column.labels = c("Total sample","Incarcerated (only)","Violent offenses (omitted)","Out for 3+ (omitted)","Gerber comparable"),
          font.size = "scriptsize",
          label = "doleacVgerberRegModelsArms",
          out = "doleacVgerber_regmodels_bytreatment.tex"
          )


m1<-lm(voted2020gen ~ as.factor(Treatment), data=data)
m2<-lm(voted2020gen ~ as.factor(Treatment), data=data %>% filter(pastincarc == 1))
m3<-lm(voted2020gen ~ as.factor(Treatment), data=data %>% filter(gerber_omit_offense != "y"))
m4<-lm(voted2020gen ~ as.factor(Treatment), data=data %>% filter(gerber_omit_timereleased == 0))
m5<-lm(voted2020gen ~ as.factor(Treatment), data=data %>% filter(gerber_sample==1))

stargazer(m1,m2,m3,m4,m5, 
          omit.stat="f", 
          title="Impact of each treatment on voting in 2020, by sample",
          dep.var.labels="", digits=1,
          dep.var.caption = "",
          column.sep.width = "-5pt",
          covariate.labels=c("Basic mailer", "No criminal record framing", "No registration form", "Extra civil rights framing"), 
          column.labels = c("Total sample","Incarcerated (only)","Violent offenses (omitted)","Out for 3+ (omitted)","Gerber comparable"),
          font.size = "scriptsize",
          label = "doleacVgerberVoteModelsArms",
          out = "doleacVgerber_votemodels_bytreatment.tex"
          )



